package com.to.aboomy.bannersample.viewpager.creator;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.to.aboomy.banner.HolderCreator;
import com.to.aboomy.bannersample.ResourceTable;
import com.to.aboomy.bannersample.util.ToastUtil;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.LayoutScatter;
import ohos.app.Context;


/**
 * ImageRoundHolderCreator
 *
 * @since 2021-08-05
 */
public class ImageRoundHolderCreator implements HolderCreator {
    @Override
    public Component createView(Context context, int integer,int index) {
        Image image = (Image) LayoutScatter.getInstance(context).parse(ResourceTable.Layout_item_round_image,null,false);
        Glide.with(context).load(integer)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .skipMemoryCache(true)
                .transform(new RoundedCorners(20))
                .into(image);
        image.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                ToastUtil.showToast(context,index+"");
            }
        });
        return image;
    }
}
